#include <stdio.h>
#include <math.h>
#define N 4

double habs(double x[])
{
	double max = 0;
	int i;
	for(i = 0;i < N;i++)
		if(fabs(x[i]) > max)
			max = fabs(x[i]);
	return max;
}

int main()
{
	int n = N;
	double a[N][N] = {{25,-41,10,-6},{-41,68,-17,10},{10,-17,5,-3},{-6,10,-3,2}};
	double v[N] = {0,0,0,1};
	double u[N] = {0,0,0,1};
	int i,j;
	double t = 0,s;
	double min = 0.00001;
	do
	{
		s = t;
		for(i = 0;i < n;i++)
		{
			v[i] = 0;
			for(j = 0;j < n;j++)
				v[i] += a[i][j]*u[j];				
		}
		t = habs(v);
		for(i = 0;i < n;i++)
			u[i] = v[i]/t;
	}while(fabs(t-s) > min);
	printf("特征值：%f\n特征向量：",t);
	for(i = 0;i < n;i++)
		printf("%f ",u[i]);
	printf("\n");
	return 0;
}
